//
//  LHYPDFEditToolView.m
//  DrawLine
//
//  Created by lhy on 2021/3/2.
//

#import "LHYPDFEditToolView.h"
#import "LHYPDFEditMoreToolVC.h"

@interface LHYPDFEditToolView () <UIPopoverPresentationControllerDelegate>

@property (weak, nonatomic) IBOutlet UIButton *btnLastStep;
@property (weak, nonatomic) IBOutlet UIButton *btnNextStep;
@property (weak, nonatomic) IBOutlet UIButton *btnPen1;
@property (weak, nonatomic) IBOutlet UIButton *btnPen2;
@property (weak, nonatomic) IBOutlet UIButton *btnPen3;
@property (weak, nonatomic) IBOutlet UIButton *btnColorBlack;
@property (weak, nonatomic) IBOutlet UIButton *btnColorBlue;
@property (weak, nonatomic) IBOutlet UIButton *btnColorGreen;
@property (weak, nonatomic) IBOutlet UIButton *btnColorYellow;
@property (weak, nonatomic) IBOutlet UIButton *btnColorRed;
@property (weak, nonatomic) IBOutlet UIButton *btnColorPurple;


@end

@implementation LHYPDFEditToolView

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)show {
    UIWindow *window = [[UIApplication sharedApplication] windows].firstObject;
    [window addSubview:self];
}

- (void)hide {
    [self removeFromSuperview];
}

/// 上一步（点击撤回）
- (IBAction)actionBtnLastStep:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PDFDrawRevocationNotification" object:@(-1)];
}
/// 下一步（点击反撤回）
- (IBAction)actionBtnNextStep:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PDFDrawRevocationNotification" object:@(1)];
}
/// 画笔种类(宽度)
- (IBAction)actionBtnPen:(UIButton *)sender {
    if (self.getDrawWidthBlock) {
        self.getDrawWidthBlock(sender.tag);
    }
}
/// 画笔颜色
- (IBAction)actionBtnColor:(UIButton *)sender {
    NSLog(@"%@", sender.backgroundColor);
    
    if (self.getDrawColorBlock) {
        self.getDrawColorBlock(sender.backgroundColor);
    }
}
/// 更多（签名/文本）
- (IBAction)actionBtnMoreTools:(UIButton *)sender {
    
    LHYPDFEditMoreToolVC *vc1 = [[LHYPDFEditMoreToolVC alloc]
                                 initWithPreferredContentSize:CGSizeMake(150, 100)
                                 dataArr:@[@"文本", @"签名"]
                                 modalPresentationStyle:UIModalPresentationPopover
                                 sourceView:self.btnMoreTools
                                 sourceRect:self.btnMoreTools.bounds
                                 permittedArrowDirections:UIPopoverArrowDirectionDown];
    vc1.popoverPresentationController.delegate = self;
    vc1.popoverType = TypeImageTitle;
    
    [self.viewController presentViewController:vc1 animated:YES completion:nil];
}



#pragma mark - UIPopoverPresentationControllerDelegate

- (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController{
    return YES;   //点击蒙版popover NO不消失， 默认YES消失
}


@end
